package com.multi.thread.chapter02.demo01;

public class Demo {
	private int num = 0;
	
	synchronized public void add(String userName) {
		try {
			if ("a".equals(userName)) {
				num = 100;
				System.out.println("a set over");
				Thread.sleep(1000);
			} else {
				num = 200;
				System.out.println("b set over");
			}
			System.out.println(userName + " num = " + num);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		Demo demo1 = new Demo();
		Demo demo2 = new Demo();
		ThreadA threada = new ThreadA(demo1);
		threada.start();
		ThreadB threadb = new ThreadB(demo2);
		threadb.start();
	}

}
